<?php
namespace app\api\controller;

use think\Controller;
use think\Db;
use app\api\model\News ;
use app\api\model\Talent;
use app\api\model\Service as service_list;
class Own extends Index
{
    //个人服务商品收藏
    public function collect_service(){
        $page = (isset($_GET['page']) && !empty($_GET['page'])) ? $_GET['page'] : 1;
        $where['uid']=input('get.uid');
        $news_list = new News('user');
        $like = $news_list->check_name($where, 'collect_id');
        $result = json_decode($like['collect_id'], true) ? json_decode($like['collect_id'], true) : array();
        if (!empty($result['serviceGoods'])) {
            $ids=implode(',',$result['serviceGoods']);
            $map['w.id']=array('in',$ids);
            $map['w.status'] = 1;
            $map['w.state'] = 1;
            $type2='zgh_shop_information i';
            $condition2 = 'w.s_id=i.id';
            $type3='zgh_service_type t';
            $condition3 = 'w.classify=t.id';
            $service_list = new service_list('service_market');
            $fields='w.*,t.t_name ';
            $count=$service_list->count($type2,$type3,$map,$condition2,$condition3);
            $data=$service_list->service_list($type2,$type3,$map,$condition2,$condition3,$fields,3,$page,'w.add_time desc');
            //分页
            $Page = new \app\api\model\Page($count,3);
            $render = $Page->render;
            $res['render']=$render;
            $res['count']=$count;
            $res['data']=$data;
            $res['shop_id']=Db::name('service_market')->alias('w')->field('w.s_id,i.name as shop_name')
                ->join($type2,$condition2,'left')
                ->join($type3,$condition3,'left')
                ->where($map)
                ->order('w.add_time desc')
                ->group('w.s_id')
                ->select();
            if ($data) {
                $this->_jsonp('200',  '查询成功', $res);
            } else {
                $this->_jsonp('1000',  '查询失败', null);
            }
        }else{
            $this->_jsonp('1000',  '没有收藏', null);
            //没有收藏
        }
    }
    //个人服务商品收藏
    public function collect_trading(){
        $page = (isset($_GET['page']) && !empty($_GET['page'])) ? $_GET['page'] : 1;
        $where['uid']=input('get.uid');
        $news_list = new News('user');
        $like = $news_list->check_name($where, 'collect_id');
        $result = json_decode($like['collect_id'], true) ? json_decode($like['collect_id'], true) : array();
        if (!empty($result['TradingDetails'])) {
            $ids=implode(',',$result['TradingDetails']);
            $map['w.id']=array('in',$ids);
            $map['w.status'] = 1;
            $type2='zgh_shop_information i';
            $condition2 = 'w.shop_id=i.id';
            $type3='zgh_market_trading_category t';
            $condition3 = 'w.category_id=t.id';
            $service_list = new service_list('market_trading');
            $fields='w.*,t.market_name ';
            $count=$service_list->count($type2,$type3,$map,$condition2,$condition3);
            $data=$service_list->service_list($type2,$type3,$map,$condition2,$condition3,$fields,3,$page,'w.time desc');
            //分页
            $Page = new \app\api\model\Page($count,3);
            $render = $Page->render;
            $res['render']=$render;
            $res['count']=$count;
            $res['data']=$data;
            $res['shop_id']=Db::name('market_trading')->alias('w')->field('w.shop_id,i.name as shop_name')
                ->join($type2,$condition2,'left')
                ->join($type3,$condition3,'left')
                ->where($map)
                ->order('w.on_time desc')
                ->group('w.shop_id')
                ->select();
            if ($data) {
                $this->_jsonp('200',  '查询成功', $res);
            } else {
                $this->_jsonp('1000',  '查询失败', null);
            }
        }else{
            $this->_jsonp('1000',  '没有收藏', null);
            //没有收藏
        }
    }
    //个人店铺收藏
    public function collect_shop(){
        $page = (isset($_GET['page']) && !empty($_GET['page'])) ? $_GET['page'] : 1;
        $map['w.shop_id'] = (isset($_GET['shop_id']) && !empty($_GET['shop_id'])) ? $_GET['shop_id'] : 1;
        $where['uid']=input('get.uid');
        $news_list = new News('user');
        $like = $news_list->check_name($where, 'collect_id');
        $result = json_decode($like['collect_id'], true) ? json_decode($like['collect_id'], true) : array();
        if (!empty($result['shop'])) {
            $ids=implode(',',$result['shop']);
            $map['w.id']=array('in',$ids);
            $map['w.static'] = 1;
            $news = new News('shop_information');
            $count=$news->count($map,'w');
            $data=Db::name('shop_information')->alias('w')->field('w.*')
                ->where($map)->order('w.time desc')
                ->limit(3)
                ->page($page)->select();
            //分页
            $Page = new \app\api\model\Page($count,3);
            $render = $Page->render;
            $res['render']=$render;
            $res['count']=$count;
            $res['data']=$data;
            if ($data) {
                $this->_jsonp('200',  '查询成功', $res);
            } else {
                $this->_jsonp('1000',  '查询失败', null);
            }
        }else{
            $this->_jsonp('1000',  '没有收藏', null);
            //没有收藏
        }
    }
    //个人课程收藏
    public function collect_course(){
        $page = (isset($_GET['page']) && !empty($_GET['page'])) ? $_GET['page'] : 1;
        $where['uid']=input('get.uid');
        $news_list = new News('user');
        $like = $news_list->check_name($where, 'collect_id');
        $result = json_decode($like['collect_id'], true) ? json_decode($like['collect_id'], true) : array();
        if (!empty($result['video'])) {
            $ids=implode(',',$result['video']);
            $map['w.id']=array('in',$ids);
            $map['w.status'] = 1;
            $news = new News('video');
            $count=$news->count($map,'w');
            $data=Db::name('video')->alias('w')->field('w.*')
                ->where($map)->order('w.time desc')
                ->limit(3)
                ->page($page)->select();
            //分页
            $Page = new \app\api\model\Page($count,3);
            $render = $Page->render;
            $res['render']=$render;
            $res['count']=$count;
            $res['data']=$data;
            if ($data) {
                $this->_jsonp('200',  '查询成功', $res);
            } else {
                $this->_jsonp('1000',  '查询失败', null);
            }
        }else{
            $this->_jsonp('1000',  '没有收藏', null);
            //没有收藏
        }
    }
    //个人资讯收藏
    public function collect_news(){
        $page = (isset($_GET['page']) && !empty($_GET['page'])) ? $_GET['page'] : 1;
        $where['uid']=input('get.uid');
        $news_list = new News('user');
        $like = $news_list->check_name($where, 'collect_id');
        $result = json_decode($like['collect_id'], true) ? json_decode($like['collect_id'], true) : array();
        if (!empty($result['news'])) {
            $ids=implode(',',$result['news']);
            $map['w.id']=array('in',$ids);
            $map['w.status'] = 1;
            $news = new News('government_work');
            $count=$news->count($map,'w');
            $data=Db::name('government_work')->alias('w')->field('w.*')
                ->where($map)->order('w.time desc')
                ->limit(3)
                ->page($page)->select();
            //分页
            $Page = new \app\api\model\Page($count,3);
            $render = $Page->render;
            $res['render']=$render;
            $res['count']=$count;
            $res['data']=$data;
            if ($data) {
                $this->_jsonp('200',  '查询成功', $res);
            } else {
                $this->_jsonp('1000',  '查询失败', null);
            }
        }else{
            $this->_jsonp('1000',  '没有收藏', null);
            //没有收藏
        }
    }
}